/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
 * Description: UDK byte order for ARM architecture header file
 * Author: -
 * Create: 2021.4.20
 */

#ifndef UDK_BYTEORDER_ARM_H
#define UDK_BYTEORDER_ARM_H

#include <stdint.h>

#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))

static inline uint16_t udk_arch_bswap16(uint16_t _x)
{
    uint16_t x = _x;

    asm volatile("rev16 %w0,%w1" : "=r"(x) : "r"(x));
    return x;
}

#define udk_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ? udk_constant_bswap16(x) : udk_arch_bswap16(x)))
#else
#define udk_bswap16(x) __builtin_bswap16(x)
#endif

#define udk_bswap32(x) __builtin_bswap32(x)
#define udk_bswap64(x) __builtin_bswap64(x)

#endif /* UDK_BYTEORDER_ARM_H */